import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:personinfo/page/person/wiget/MessageInfo.dart';
import 'package:personinfo/utils/ColorUtil.dart';

import '../../../widgets/common/CommonWidget.dart';
import '../../../widgets/common/keepAlive/KeepAliveWrapper.dart';

class MessageNotify extends StatefulWidget {
  Map arguments;
  MessageNotify({super.key,required this.arguments});

  @override
  State<StatefulWidget> createState() => _MessageNotify();
}

class _MessageNotify extends State<MessageNotify> with SingleTickerProviderStateMixin {
  late TabController _tabController;
  List tabs = ["全部", "订单消息", "系统消息"];
  final List _pages = [
    const MessageInfo(orderNum: "X1111-待处理",),
    const MessageInfo(orderNum: "X22222-待确认",),
    const MessageInfo(orderNum: "X3333-待支付",),
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: tabs.length,initialIndex: widget.arguments['index'] ?? 0, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  Scaffold(
      appBar: commonWidget.appBar(
        title: const Text("消息通知") ,
        leading: GestureDetector(onTap: (){Navigator.pop(context);},child: const Icon(Icons.keyboard_arrow_left),),
          bottom: PreferredSize(
              preferredSize: Size.fromHeight(50.0),
              child: Container(
                decoration: BoxDecoration(
                    color: Theme.of(context).colorScheme.onPrimary
                ),
                child: TabBar(
                  controller: _tabController,
                  padding: EdgeInsets.fromLTRB(1, 0, 1, 1),
                  unselectedLabelColor: Colors.black,
                  labelStyle: TextStyle(fontWeight: FontWeight.bold,color: Colors.black),
                  indicatorColor:  ColorUtil.primaryBgColor,
                  tabs: tabs.map((e) => SizedBox(width: 100,child: Tab(text: e,))).toList(),
                ),
              )
          ),
        actions: [
          Text("全部已读"),
          SizedBox(width: 16,)
        ]
      ),
      body: TabBarView(
        //构建
        controller: _tabController,
        children: _pages.map((e) {
          return KeepAliveWrapper(
            child: Container(
              alignment: Alignment.center,
              child: e,
            ),
          );
        }).toList(),
      ),
    );
  }

  @override
  void dispose() {
    // 释放资源
    _tabController.dispose();
    super.dispose();
  }
}
